<template>
    <div>
       <div class="tableHeader">
        <div class="tableHeaderTitle">图库列表</div>
            <div class="tableHeaderMenu">
                <el-button-group>
                    <el-button icon="el-icon-refresh" @click="refreshData" size="mini"></el-button>
                </el-button-group>
            </div>
        </div>

        <el-table ref="multipleTable" :data="galleryImageData" tooltip-effect="dark" style="width: 100%">
            <el-table-column label="序号" type="index" width="80"></el-table-column>
            <el-table-column prop="cil_title" label="图片标题"></el-table-column>
            <el-table-column label="图片预览">
                <template slot-scope="scope">
                    <img :src="scope.row.cil_url" style="width:auto;height:30px" />
                </template>
            </el-table-column>
            <el-table-column prop="cl_type" label="图片大小">
                <template slot-scope="scope">
                    {{scope.row.cil_size}} kb
                </template>
            </el-table-column>
            <el-table-column prop="cil_format" label="图片类型"></el-table-column>
            <el-table-column label="操作" fixed="right" width="260">
                <template slot-scope="scope">
                    <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
    import { mapState,mapMutations } from 'vuex'
    export default {
        //数据源
        data(){
            return {

            }
        },
        //初始化函数
        mounted() {
            this.initData('init');
        },
        //计算属性
        computed: {
            ...mapState({
                galleryImageData : state => state.GalleryImageListModule.galleryImageData
             })
        },
        //组件方法
        methods: {
            refreshData(){
                this.initData('init');
            },
            initData(type){

                if(type == 'init'){
                    this.$myLoading.startLoading()
                }
                
                this.$http.getHttp(
                    this.$API.cmsImageLibrarySearch + "/skip/0/limit/999/cil_is_delete/0",
                    rs => {
                        this.$store.commit('GalleryImageListModule/updateGalleryImageData',rs.data)

                        if(type == 'init'){
                            this.$myLoading.endLoading()
                        }
                        
                    }
                )
            },
            handleDelete(index,item){

                var params = {
                    delete_where  : "cil_id",
                    cil_id        : item.cil_id,
                    cil_is_delete : 1
                }

                this.$myPop.confirmBox("确认操作","确定要删除该友情链接吗？",()=>{
                    this.$myLoading.startLoading()
                    this.$http.postHttp(
                        this.$API.cmsImageLibraryDelete,
                        params,
                        rs => {
                            this.$myLoading.endLoading()
                            this.$myPop.SuccessMessage()
                            this.initData('update')
                        }
                    )
                })
            }
        }
    }
</script>

<style lang="stylus" scoped>
@import '~PUBLIC_CSS';
</style>